package com.xiaoshuidi.cloud.module.contract.controller.app.contract;

import com.xiaoshuidi.cloud.framework.common.exception.ServiceException;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.stay.ContractStayRespVO;
import com.xiaoshuidi.cloud.module.contract.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.contract.service.contract.ContractStayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.error;
import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 入住交房")
@RestController
@RequestMapping(ApiConstants.NAME + "/app/stay")
@Validated
public class AppStayController {
    @Resource
    private ContractStayService stayService;

    /**
     * 获得入住交割信息
     */
    @GetMapping("/get")
    @Operation(summary = "获得入住交割")
    @Parameter(name = "id", description = "合同ID", required = true, example = "1024")
    public CommonResult<ContractStayRespVO> getStay(@RequestParam("id") Long id) {
        try {
            return success(stayService.getStay(id));
        } catch (ServiceException e) {
            return error(e.getCode(),e.getMessage());
        }
    }

    /**
     * 确认交房
     */
    @GetMapping("/confirm")
    @Operation(summary = "确认交房")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('contract:stay:query')")
    public CommonResult<Boolean> confirmDelivery(@RequestParam("id") Long id) {
        try {
            stayService.confirmDelivery(id);
            return success(true);
        } catch (ServiceException e) {
            return error(e.getCode(),e.getMessage());
        }
    }

}
